<?php

namespace Admin\Models\school;

use Admin\Models\BaseModel;
class XhschoolAppgroup extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iSAGId;

    /**
     *
     * @var string
     */
    public $sSAGName;

    /**
     *
     * @var integer
     */
    public $iSAType;

    /**
     *
     * @var integer
     */
    public $iSchoolId;

    /**
     *
     * @var integer
     */
    public $bSAGEnable;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tCreateDate;

    /**
     *
     * @var string
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     */
    public $tLastModifyDate;

    /**
     *
     * @var string
     */
    public $iLastModifyUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setSource("XHSchool_AppGroup");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHSchool_AppGroup';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhschoolAppgroup[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhschoolAppgroup
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 根据id数组删除相应记录
     *
     * @param $idArr
     * @return mixed
     *
     * create by ck 20160930
     */
    public static function deleteRecordById($idArr)
    {
        return self::find(array(
            'conditions' => 'iSAGId IN ({idArr:array}) AND bDelete = 0',
            'bind'       => ['idArr' => $idArr]
        ))->delete();
    }

    /**
     * 根据数据新建或修改数据并返回modal
     *
     * @param array $data
     * @return XhschoolAppgroup
     *
     * create by ck 20160701
     * modify by ck 20160930    结构化简
     */
    public static function createRecord($data)
    {
        $obj = $data['iSAGId'] ? self::findFirst($data['iSAGId']) : new self;
        $obj->assign($data);
        return $obj;
    }

}
